<?php
namespace Auth\Model;

use Zend\Db\Adapter\Adapter;
use Zend\Db\Sql\Sql;
use Zend\Stdlib\Hydrator\ClassMethods;

class SettingMapper 
{
    protected $tableName = 'settings';
    protected $sql;
    protected $dbAdapter;
    
    public function __construct(Adapter $dbAdapter)
    {
        $this->dbAdapter = $dbAdapter;
        $this->sql = new Sql($dbAdapter);
        $this->sql->setTable($this->tableName);
    }
    
    public function getValue($key)
    {
        $select = $this->sql->select();
        $select->where(array('key' => $key));
        $statement = $this->sql->prepareStatementForSqlObject($select);
        $result = $statement->execute()->current();
        if(!$result)
            return null;
        return $result['value'];
    }
    
    public function getMailConfig()
    {
        $config = array();
        $keys = array(
            'host',
            'username',
            'password',
            'ssl',
            'port',
            'connection_class'
        );
        foreach ($keys as $key) {
            $config[$key] = $this->getValue([$key]);
        }
        return $config;
    }
}